package com.fr71.project.dm.listener;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.codec.bytes.ByteArrayEncoder;

public class TcpInitChannel extends ChannelInitializer<SocketChannel> {
    private final ChannelHandler channelHandler;

    public TcpInitChannel(ChannelHandler channelHandler) {
        this.channelHandler = channelHandler;
    }

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        socketChannel.pipeline().addLast("decoder", new LengthFieldBasedFrameDecoder(1024 * 1024, 8, 2));
        socketChannel.pipeline().addLast("encoder", new ByteArrayEncoder());
        socketChannel.pipeline().addLast(channelHandler);
    }
}